﻿//-----------------------------------------------------------------------
// <copyright file="WebflowElementResultAdapterBase`1.cs" company="Sławomir Rosiek">
//     Copyright (c) Sławomir Rosiek. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Rosieks.Web.Flow
{
    using System;
    using System.Web.Mvc;
    using Rosieks.Web.Flow.Metadata;

    public abstract class WebflowElementResultAdapterBase<TElement> : IWebflowElementResultAdapter where TElement : class, IExecutionObject
    {
        public abstract ActionResult CreateResult(TElement element, ControllerContext context);

        ActionResult IWebflowElementResultAdapter.CreateResult(IExecutionObject element, ControllerContext context)
        {
            var e = element as TElement;
            if (e == null)
            {
                // TODO: Better exception description.
                throw new ArgumentException("Invalid type");
            }

            return this.CreateResult(e, context);
        }
    }
}
